//@author A0087191Y
package net.mysoc.w111j.service.filters;

import net.mysoc.w111j.model.Expense;
import net.mysoc.w111j.model.PaymentType;

/**
 * An {@code ExpenseFilter} matching expenses that have a given {@code PaymentType}.
 */
public class PaymentTypeExpenseFilter implements ExpenseFilter {
    private final PaymentType paymentType;

    public PaymentTypeExpenseFilter(PaymentType paymentType) {
        if (paymentType == null) {
            throw new NullPointerException("PaymentType should not be null.");
        }
        this.paymentType = paymentType;
    }

    public PaymentType getPaymentType() {
        return paymentType;
    }

    @Override
    public boolean shouldSelect(Expense expense) {
        return paymentType.equals(expense.getPaymentType());
    }

    @Override
    public String getDescription() {
        return paymentType.toString();
    }
}
